<?php

namespace app\common\model\business;

use think\Model;

class Record extends Model
{
    //
    protected $name = 'business_record';
    
    //指定一个自动设置的时间字段
    //开启自动写入
    protected $autoWriteTimestamp = true;

    //设置字段的名字
    protected $createTime = "createtime"; //插入的时候设置的字段名

    //禁止 写入的时间字段
    protected $updateTime = false;

    // 追加字段
    protected $append  = [
        'createtime_text', 
    ];

    public function getCreatetimeTextAttr($value, $data)
    {
        $createtime = isset($data['createtime']) ? $data['createtime'] : '';

        if(empty($createtime))
        {
            return '';
        }
        
        return date('Y-m-d H:i', $createtime);
    }

    //关联查询
    public function business()
    {
        return $this->belongsTo('app\common\model\business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}